#encoding=utf8
'''
Created on Dec 19, 2014

@author: jingyang <jingyang@smalltreemedia.com>
'''
from celery.task import task
import gspread

import settings
from django.core.mail import mail_admins
import datetime
from app_info.models import AppVersion


@task()
def update_google_sheet(file_name, data_list):
    try:
        gc = gspread.login(settings.WRITER_EMAIL, settings.WRITER_PWD)
        wks = gc.open(file_name).sheet1
        wks.append_row(data_list)
        print 'updated!'
    except Exception, e:
        mail_admins('Update Google Sheet Failed.',
            'update google sheet: %s failed. (%s %s)' % (file_name, data_list[0], e), True)
        print e
